package com.sc.base.admin.repository;


import com.sc.base.admin.comm.entity.SysDictionaryEntity;
import com.sc.base.admin.comm.global.ScBaseCommRedisKey;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by liuwei on 2019-07-06 13:15:27
 */

@Service
public class RedisRepository {

    private static final Logger logger = LoggerFactory.getLogger(RedisRepository.class);

    @Autowired
    private  JedisService jedisService;


    public  String getValue(String  key){
        try{
            String value = jedisService.hget(ScBaseCommRedisKey.sys_dictionary_key, key);
            return value;
        }catch (Exception e){
            logger.error("ProfitConfig error: key is null:{}",key);
        }
        return "";
    }

    public  void put(List<SysDictionaryEntity> dictionaryEntityList){
        for(SysDictionaryEntity sysDictionaryEntity:dictionaryEntityList){
            try {
                long hset = jedisService.hset(ScBaseCommRedisKey.sys_dictionary_key, sysDictionaryEntity.getDicName(), sysDictionaryEntity.getDicValue());
            } catch (Exception e) {
                logger.error("RedisRepository error: set key={} is null:{}",sysDictionaryEntity.getDicName(),e);
            }
        }

    }
}
